home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 May / PCWorld_2007-05_cd.bin / audio-video / mediacenter / MediaCenter120207.exe / Media Jukebox / Data / Default Resources / Media Center Help.chm / doctohelp.js < prev    next >
Encoding:
JavaScript  |  2007-04-03  |  11.3 KB  |  465 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // dhtml functions: require IE4 or later
  4. //
  5. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  6.  
  7. var POPUP_COLOR = 0xffffe0;
  8. var IMAGE_OPEN = "%OpenPictureContentsTopic%";
  9. var IMAGE_CLOSE = "%ClosePictureContentsTopic%";
  10. var INDEX_SELECTED = "%OpenPictureNavigatorIndex%";
  11. var INDEX_UNSELECTED = "%ClosePictureNavigatorIndex%";
  12. var CONTENTS_SELECTED = "%OpenPictureNavigatorContents%";
  13. var CONTENTS_UNSELECTED = "%ClosePictureNavigatorContents%";
  14.  
  15. function dhtml_popup(url)
  16. {
  17.     var pop, main, body, x, y;
  18.  
  19.     // no url? then hide the popup
  20.     if (url == null || url.length == 0)
  21.     {
  22.         pop = document.all["popupFrame"];
  23.         if (pop != null)
  24.             pop.style.display = "none";
  25.         return;
  26.     }
  27.  
  28.     // if the popup frame is already open, close it first
  29.     if (dhtml_popup_is_open())
  30.     {
  31.         // the main window is the parent of the popup frame
  32.         main = window.parent;
  33.         body = main.document.body;
  34.         pop = main.document.all["popupFrame"];
  35.  
  36.         // add the popup origin to the event coordinates
  37.         x = pop.offsetLeft + window.event.offsetX;
  38.         y = pop.offsetTop + window.event.offsetY;
  39.  
  40.         // hide the popup frame
  41.         pop.style.display = "none";
  42.     }
  43.     else
  44.     {
  45.         // the main window is the current window
  46.         main = window;
  47.         body = document.body;
  48.         pop = document.all["popupFrame"];
  49.  
  50.         // use the event coordinates for positioning the popup
  51.         x = window.event.x;
  52.         y = window.event.y;
  53.  
  54.         // account for the scrolling text region, if present
  55.         var nstx = document.all["nstext"];
  56.         if (nstx != null)
  57.         {
  58.             if (document.body.scroll == "no")
  59.                 y += nstx.scrollTop - nstx.offsetTop;
  60.         }
  61.         // get the popup frame, creating it if needed
  62.         if (pop == null)
  63.         {
  64.             var div = document.all["popupDiv"];
  65.             if (div == null)
  66.                 return;
  67.  
  68.             div.innerHTML = "<iframe id=\"popupFrame\" frameborder=\"none\" scrolling=\"none\" style=\"display:none\"></iframe>";
  69.             pop = document.all["popupFrame"];
  70.         }
  71.     }
  72.  
  73.     // get frame style
  74.     var sty = pop.style;
  75.  
  76.     // load url into frame
  77.     pop.src = url;
  78.  
  79.     // initialize frame size/position
  80.     sty.position  = "absolute";
  81.     sty.border    = "1px solid #cccccc";
  82.     sty.posLeft   = x + body.scrollLeft     - 30000;
  83.     sty.posTop    = y + body.scrollTop + 15 - 30000;
  84.     var wid       = body.clientWidth;
  85.     sty.posWidth  = (wid > 500)? wid * 0.6: wid - 20;
  86.     sty.posHeight = 0;
  87.  
  88.     // wait until the document is loaded to finish positioning
  89.     main.setTimeout("dhtml_popup_position()", 100);
  90. }
  91.     
  92. function dhtml_popup_is_open()
  93. {
  94.     if (window.name != "")
  95.         return window.name != "right";
  96.     else
  97.         return window.location.href != window.parent.location.href;
  98. }
  99.  
  100. function dhtml_popup_position()
  101. {
  102.     // get frame
  103.     var pop = document.all["popupFrame"];
  104.     var frm = document.frames["popupFrame"];
  105.     var sty = pop.style;
  106.  
  107.     if (frm.document.readyState != "complete")
  108.     {
  109.         window.setTimeout("dhtml_popup_position()", 100);
  110.         return;
  111.     }
  112.  
  113.     // get containing element (scrolling text region or document body)
  114.     var body = document.all["nstext"];
  115.     if (body == null)
  116.         body = document.body;
  117.  
  118.     // hide navigation/nonscrolling elements, if present
  119.     dhtml_popup_elements(frm.self.document);
  120.  
  121.     // get content size
  122.     sty.display = "block";
  123.     frm.scrollTo(0,1000);
  124.     sty.posHeight = frm.self.document.body.scrollHeight + 20;
  125.  
  126.     // make content visible
  127.     sty.posLeft  += 30000;
  128.     sty.posTop   += 30000;
  129.  
  130.     // adjust x position
  131.     if (sty.posLeft + sty.posWidth + 10 - body.scrollLeft > body.clientWidth)
  132.         sty.posLeft = body.clientWidth  - sty.posWidth - 10 + body.scrollLeft;
  133.  
  134.     // if the frame fits below the link, we're done
  135.     if (sty.posTop + sty.posHeight - body.scrollTop < body.clientHeight)
  136.         return;
  137.  
  138.     // calculate how much room we have above and below the link
  139.     var space_above = sty.posTop - body.scrollTop;
  140.     var space_below = body.clientHeight - space_above;
  141.     space_above -= 35;
  142.     space_below -= 20;
  143.     if (space_above < 50) space_above = 50;
  144.     if (space_below < 50) space_below = 50;
  145.  
  146.     // if the frame fits above or we have a lot more room there, move it up and be done
  147.     if (sty.posHeight < space_above || space_above > 2 * space_below)
  148.     {
  149.         if (sty.posHeight > space_above)
  150.             sty.posHeight = space_above;
  151.         sty.posTop = sty.posTop - sty.posHeight - 30;
  152.         return;
  153.     }
  154.  
  155.     // adjust frame height to fit below the link
  156.     sty.posHeight = space_below;
  157. }
  158.  
  159. function dhtml_popup_elements(doc)
  160. {
  161.     // hide navigation bar, if present
  162.     var nav = doc.all["ienav"];
  163.     if (nav != null)
  164.         nav.style.display = "none";
  165.  
  166.     // set popup color and remove background image
  167. //    doc.body.style.backgroundColor = POPUP_COLOR;
  168. //    doc.body.style.backgroundImage = "none";
  169.  
  170.     // reset popup color of title row, if present
  171.     var trow = doc.all["TitleRow"];
  172.     if (trow != null)
  173.         trow.style.backgroundColor = POPUP_COLOR;
  174.  
  175.     // reset border/color of nonscrolling banner, if present
  176.     var nsb = doc.all["nsbanner"];
  177.     if (nsb != null)
  178.     {
  179.         nsb.style.borderBottom = "0px";
  180.         nsb.style.backgroundColor = POPUP_COLOR;
  181.     }
  182.  
  183.     // reset background image/color of scrolling text region, if present
  184.     var nstx = doc.all["nstext"];
  185.     if (nstx != null)
  186.     {
  187.         nstx.style.backgroundColor = POPUP_COLOR;
  188.         nstx.style.backgroundImage = "none";
  189.     }
  190. }
  191.  
  192. function dhtml_nonscrolling_resize()
  193. {
  194.     if (document.body.clientWidth == 0)
  195.         return;
  196.  
  197.     var oBanner= document.all.item("nsbanner");
  198.     var oText= document.all.item("nstext");
  199.  
  200.     if (oText == null)
  201.         return;
  202.  
  203.     var oTitleRow = document.all.item("TitleRow");
  204.  
  205.     if (oTitleRow != null)
  206.         oTitleRow.style.padding = "0px 10px 0px 22px;";
  207.  
  208.     if (oBanner != null)
  209.     {
  210. ////        document.body.scroll = "no"
  211. ////        oText.style.overflow = "auto";
  212.          oBanner.style.width = document.body.clientWidth;
  213.         oText.style.paddingRight = "20px"; // Width issue code
  214.         oText.style.width = document.body.clientWidth;
  215.         oText.style.top = 0;  
  216.  
  217.         if (document.body.offsetHeight > oBanner.offsetHeight + 4)
  218.             oText.style.height = document.body.offsetHeight - oBanner.offsetHeight - 4;
  219.         else
  220.             oText.style.height = 0;
  221.     }    
  222.  
  223. //    try{nstext.setActive();} //allows scrolling from keyboard as soon as page is loaded. Only works in IE 5.5 and above.
  224. //    catch(e){}
  225.  
  226.     window.onresize = d2hnsresize;
  227.     window.onbeforeprint = d2h_before_print;
  228.     window.onafterprint = d2h_after_print;
  229.  
  230. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  231. //
  232. // d2h functions: browser-independent
  233. //
  234. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  235.  
  236. function d2hie()
  237. {
  238.     var ie = navigator.userAgent.toLowerCase().indexOf("msie");
  239.     return ie != -1 && parseInt(navigator.appVersion) >= 4;
  240. }
  241.  
  242. function d2hpopup(url)
  243. {
  244.     // use dhtml if we can
  245.     if (d2hie())
  246.     {
  247.         dhtml_popup(url);
  248.         return false;
  249.     }
  250.  
  251.     // use regular popups
  252.     if (url != null && url.length > 0)
  253.     {
  254.         var pop = window.open(url, '_d2hpopup', 'resizable=1,toolbar=0,directories=0,status=0,location=0,menubar=0,height=300,width=400');
  255.         pop.focus();                 // if the popup was already open
  256.         pop.onblur = "self.close()"; // doesn't work, not sure why...
  257.     }
  258.  
  259.     // and ignore the click
  260.     return false;
  261. }
  262.  
  263. function d2hwindow(url, name)
  264. {
  265.     if (name != 'main')
  266.     {
  267.         window.open(url, name, 'scrollbars=1,resizable=1,toolbar=0,directories=0,status=0,location=0,menubar=0,height=300,width=400');
  268.         return false;
  269.     }
  270.     return true;
  271. }
  272.  
  273. function d2hcancel(msg, url, line)
  274. {
  275.     return true;
  276. }
  277.  
  278. function d2hload()
  279. {
  280.     window.focus();
  281.     window.onerror = d2hcancel;
  282.     if (window.name == '_d2hpopup')
  283.     {
  284.         var major = parseInt(navigator.appVersion);
  285.         if (major >= 4)
  286.         {
  287.             var agent = navigator.userAgent.toLowerCase();
  288.             if (agent.indexOf("msie") != -1)
  289.                 document.all.item("ienav").style.display = "none";
  290.             else
  291.                 document.layers['nsnav'].visibility = 'hide';
  292.         }
  293.     }
  294. }
  295.  
  296. function d2hframeload()
  297. {
  298.     // for compatibility with HTML generated by earlier versions
  299. }
  300.  
  301. function d2htocload()
  302. {
  303.     if (d2hie())
  304.     {
  305.         var id, elt;
  306.         var count = document.all.length;
  307.  
  308.         for (i = 0; i < count; i++)
  309.         {
  310.             elt = document.all.item(i);
  311.  
  312.             if (elt.id.substring(0, 1) == "c")
  313.                 elt.style.display = "none";
  314.  
  315.             else if (elt.id.substring(0, 2) == "mi")
  316.                 d2himage(elt, IMAGE_CLOSE, "closed.gif");
  317.         }
  318.     }
  319. }
  320.  
  321. function d2hclick()
  322. {
  323.     if (d2hie())
  324.     {
  325.         var id = window.event.srcElement.id;
  326.  
  327.         var n = id.substring(0, 1);
  328.         if (id.substring(0, 1) != "m")
  329.             return;
  330.  
  331.         var sub = id.substring(2);
  332.         var elt = document.all.item("c" + sub);
  333.         var img = document.all.item("mi" + sub);
  334.  
  335.         if (elt != null)
  336.         {
  337.             if (elt.style.display == "none")
  338.             {
  339.                 elt.style.display = "";
  340.                 d2himage(img, IMAGE_OPEN, "open.gif");
  341.             }
  342.             else
  343.             {
  344.                 elt.style.display = "none";
  345.                 d2himage(img, IMAGE_CLOSE, "closed.gif");
  346.             }
  347.         }
  348.     }
  349. }
  350.  
  351. // Sets a specified relative URL of image to specified HTML element
  352. function d2himage(element, image, def)
  353. {
  354.     if (element != null)
  355.     {
  356.         // Sets the default image if open image is not initialized
  357.         if (image.substring(0, 2) == "%O")
  358.             image = def;
  359.  
  360.         // Sets the default image if close image is not initialized
  361.         else if (image.substring(0, 2) == "%C")
  362.             image = def;
  363.  
  364.         // Hide element if image is missing
  365.         if (image == "")
  366.             element.style.visibility = "hidden";
  367.  
  368.         // Sets the specified image to element and displays it
  369.         else
  370.         {
  371.             element.src = image;
  372.             element.style.visibility = "visible";
  373.         }    
  374.     }
  375. }
  376.  
  377. function d2hswitchpane(id)
  378. {
  379.     var sel, unsel, selimg, unselimg;
  380.     var prefix = id.substring(0, 8);
  381.     if (prefix == "D2HIndex")
  382.     {
  383.         sel = document.all("D2HIndex");
  384.         unsel = document.all("D2HContents");
  385.         selimg = INDEX_SELECTED;
  386.         unselimg = CONTENTS_UNSELECTED;
  387.     }
  388.     else if (prefix == "D2HConte")
  389.     {
  390.         sel = document.all("D2HContents");
  391.         unsel = document.all("D2HIndex");
  392.         selimg = CONTENTS_SELECTED;
  393.         unselimg = INDEX_UNSELECTED;
  394.     }
  395.  
  396.     if (sel != null)
  397.     {
  398.         sel.className = sel.id + "Selected";
  399.         var selimgelm = document.all(sel.id + "Image");
  400.         d2himage(selimgelm, selimg, "");
  401.     }
  402.  
  403.     if (unsel != null)
  404.     {
  405.         unsel.className = unsel.id + "Unselected";
  406.         var unselimgelm = document.all(unsel.id + "Image");
  407.         d2himage(unselimgelm, unselimg, "");
  408.     }
  409. }
  410.  
  411. function d2hactivepane()
  412. {
  413.     var id = "D2HContents";
  414.     var frms = window.parent.frames;
  415.     if (frms.length < 2)
  416.         return id;
  417.  
  418.     var frm = frms("left");
  419.     if (frm == null)
  420.         return id;
  421.  
  422.     var body = frm.document.body;
  423.     if (body != null)        
  424.         id = body.id;
  425.  
  426.     return id;                
  427. }
  428.  
  429. function d2hnsresize()
  430. {
  431.     if (d2hie())
  432.     {
  433.         dhtml_nonscrolling_resize();
  434.         var id = d2hactivepane();
  435.         d2hswitchpane(id);
  436.     }
  437. }
  438.  
  439. function d2h_before_print()
  440. {
  441.         document.body.scroll = "yes";
  442.     var oText = document.all.item("nstext");
  443.     if (oText != null)
  444.     {
  445.         oText.style.overflow = "visible";
  446.         oText.style.width = "100%";
  447.     }
  448.     var nav = document.all["ienav"];
  449.     if (nav != null)
  450.         nav.style.display = "none";
  451.     var oBanner = document.all.item("nsbanner");
  452.     if (oBanner != null)
  453.     {
  454.         oBanner.style.borderBottom = "0px";
  455.         oBanner.style.margin = "0px 0px 0px 0px";
  456.         oBanner.style.width = "100%";
  457.     }
  458. }
  459.  
  460. function d2h_after_print()
  461. {
  462.     document.location.reload();
  463. }
  464.